class Product < ActiveRecord::Base
  default_scope :order => 'id'
  has_many :line_items
  validates :title, :description, :image_url, :presence =>true
  before_destroy :ensure_not_referenced_by_any_line_item
  private
  def ensure_not_referenced_by_any_line_item
    if line_items.empty?
    return true
    else
      errors.add(:base,"Line Items present")
    return false
    end
  end
end
